package com.cyou.gamehistory.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.cyou.gamehistory.entity.Manager;
import com.cyou.gamehistory.util.ApplicationConstants;

/**
 * 用户登录拦截器
 * 
 * @author wangzhang date 2012-12-24 下午7:14:51
 */
public class UserLoginInterceptor extends HandlerInterceptorAdapter {

	private Logger log = Logger.getLogger(this.getClass());

	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		HttpSession session = request.getSession();
		Manager manager = (Manager) session.getAttribute(ApplicationConstants.ADMIN_SESSION_MANAGER);
		if (manager == null) {
			log.info("后台未登陆...");
			response.sendRedirect(request.getContextPath()+ "/a/login");
			return false;
		}
		return true;
	}

}
